﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using ZLDC.Common.Estate;
using ZLDC.DAL.Estate;

namespace ZLDC.Estate.Ajax
{
    public partial class GetDeptAuto : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (Request.QueryString["dpname"] != null && Request.QueryString["dpname"] != "")
                {
                    bool fgs = false;
                    if (Request.QueryString["fgs"] != null && Request.QueryString["fgs"].Trim() != string.Empty)
                    {
                        fgs = true;
                    }

                    string result = HttpUtility.UrlDecode(Request.QueryString["dpname"].Trim());

                    Response.Write(GetLikeDeptName(result, fgs));
                    Response.End();
                }
            }
        }

        private String GetLikeDeptName(String prefixText, bool bFgs)
        {
            StringBuilder sbstr = new StringBuilder();
            string sKey = SafeRequest(prefixText.Trim());

            System.Data.DataTable dt = DeptDAL.GetDeptData(sKey).Tables[0];

            _Json json = new _Json(dt);
            return "{record:" + json.ToJson() + "}";
        }

        public static string SafeRequest(object obj)
        {
            if (obj == null)
                return "";
            else
                return obj.ToString().Replace("'", "''");
        }

    }
}
